package com.zjx.mhxykey.root;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;


public class Execute {
    public static ClipboardManager clipboard;

    /**
     * 截屏保存
     */
    @SuppressLint("SdCardPath")
    public static void screenshots(String filePath, RootCmd.RootCallBack callBack) {
        RootCmd.execRootCmdSilent("screencap -p " + filePath,callBack);
    }


    /**
     * 返回主界面
     */
    public static void home(RootCmd.RootCallBack callBack) {
        RootCmd.execRootCmdSilent("input keyevent KEYCODE_HOME",callBack);
    }

    /**
     * 复制文本到粘贴板
     *
     * @param text    文本内容
     */
    public static void copy(String text,Context context) {
        if (clipboard == null) clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("label", text);
        clipboard.setPrimaryClip(clip);
    }

    //系统剪贴板-获取:
    public static void paste(RootCmd.RootCallBack callBack) {
        RootCmd.execRootCmdSilent("input keyevent 279",callBack);
    }

    /**
     * 点击界面 坐标
     *
     * @param x x坐标
     * @param y y坐标
     */
    @SuppressLint("DefaultLocale")
    public static void click(int x, int y,RootCmd.RootCallBack callBack) {
        String content = String.format("input tap %d %d", x, y);
        RootCmd.execRootCmdSilent(content,callBack);
    }

    /**
     * 长点坐标
     *
     * @param start_x  起点x坐标
     * @param start_y  起点y坐标
     * @param end_x    终点x坐标
     * @param end_y    终点y坐标
     * @param duration 按住时间
     */
    @SuppressLint("DefaultLocale")
    public static void longClick(int start_x, int start_y, int end_x, int end_y, int duration,RootCmd.RootCallBack callBack) {
        String content = String.format("input touchscreen  swipe %d %d %d %d %d", start_x, start_y, end_x, end_y, duration);
        RootCmd.execRootCmdSilent(content,callBack);

    }

    /**
     * 点击滑动
     *
     * @param start_x 起点x坐标
     * @param start_y 起点y坐标
     * @param end_x   终点x坐标
     * @param end_y   终点y坐标
     */
    @SuppressLint("DefaultLocale")
    public static void swipe(int start_x, int start_y, int end_x, int end_y,RootCmd.RootCallBack callBack) {
        String content = String.format("input swipe %d %d %d %d", start_x, start_y, end_x, end_y);
        RootCmd.execRootCmdSilent(content,callBack);
    }
}
